
def expected_coin_toss(n, m)
  ((1 << (n + 1)) - (1 << (m + 1))).to_s + '.00' #2^(n+1) - 2^(m+1)
  #(2 ** (n+1) - 2 ** (m+1)).to_s + '.00'
end

def from_stdin
  tests = Array.new
  num_tests = gets.to_i
  num_tests.times do
    tests << gets.split.map{|x| x.to_i}
  end
  num_tests.times do
    nm = tests.shift
    puts expected_coin_toss(nm[0],nm[1])
  end
end

from_stdin

def from_file filename
  tests = Array.new
  file = File.open(filename)
  num_tests = file.gets.to_i
  num_tests.times do
    tests << file.gets.split.map{|x| x.to_i}
  end
  
  count = 1
  outfile = File.open(filename.gsub(/(input)(\d\d).txt$/, 'output\2.txt')).each_line do |line|
    answer_str = line.gsub(/\n/, '')
    inp = tests.shift
    result_str = expected_coin_toss(inp[0],inp[1])
    if answer_str != result_str
      puts "does not match line # #{count}"
      puts "Answer = \n#{answer_str} vs Result = \n#{result_str}"
      p answer_str.chars.with_index.to_a - result_str.chars.with_index.to_a
      return
    end
      #p "Answer = \n #{answer} vs Result = \n #{result}"
    count += 1
  end
  p "SUCCESS with file #{filename.match(/(input\d\d).txt$/)[0]}"
end

file_num = "00"
10.times do
  from_file 'C:\Users\kirill\Documents\interview_street\Coin-Tosses_testcases\input' + file_num + '.txt'
  file_num.succ!
end

